package com.jane.addressbook.servlet;

import java.io.IOException;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jane.addressbook.jdbc.DBConnection;
import com.jane.addressbook.manager.AddressbookManager;

public class Delete extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7454727330524620751L;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)  
            throws ServletException, IOException {  
          
        this.doPost(req, resp);  
    }  
  
      
    public void doPost(HttpServletRequest req, HttpServletResponse resp)  
            throws ServletException, IOException {
    	Connection conn = DBConnection.getConnection();
    	AddressbookManager manager = new AddressbookManager(conn);   
        int id = Integer.parseInt(req.getParameter("id"));  
        manager.delete(id);     
        resp.sendRedirect("list");  
        DBConnection.closeConnection(conn);
    }  

}
